﻿using DA.Core.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;

namespace DA.HMI.Controls
{
    class HcRichTextBox : RichTextBox
    {
        public HcRichTextBox()
        {
            IsReadOnly = true;
            VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            
        }
        public static readonly DependencyProperty HcTextColorProperty = 
            DependencyProperty.Register("HcTextColor", typeof(SolidColorBrush), typeof(HcRichTextBox), new PropertyMetadata(System.Windows.Media.Brushes.Black));
        public SolidColorBrush HcTextColor
        {
            get { return (SolidColorBrush)GetValue(HcTextColorProperty); }
            set { SetValue(HcTextColorProperty, value); }
        }

        public string AddText
        {
            get { return (string)GetValue(AddTextProperty); }
            set { SetValue(AddTextProperty, value); }
        }
        public static readonly DependencyProperty AddTextProperty = DependencyProperty.Register("AddText", typeof(string), typeof(HcRichTextBox), new PropertyMetadata(string.Empty, OnPropertyChanged));

        private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var myRichTextBox = d as HcRichTextBox ?? new HcRichTextBox();
            Run r = new Run(myRichTextBox.AddText);
            //r.Foreground = System.Windows.Media.Brushes.Red;
            r.Foreground = myRichTextBox.HcTextColor;
            Paragraph para = new Paragraph();
            para.Inlines.Add(r);
            myRichTextBox.Document.Blocks.Add(para);
            myRichTextBox.ScrollToEnd();
        }
    }
}
